package com.appspot.mypartymanager.servlet;

import java.io.IOException;
import javax.servlet.http.*;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

@SuppressWarnings("serial")
public class MypartymanagerServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		
		String action = req.getParameter("action");
		String requestURI = req.getParameter("requestURI");
		
		
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();

		/*if (user != null) {
			resp.setContentType("text/html");
			resp.getWriter().println("Hello, " + user.getNickname() + " | <a href=\"" + userService.createLogoutURL(req.getRequestURI()) + "\">Logout</a>");
		} else {
			resp.sendRedirect(userService.createLoginURL(req.getRequestURI()));
		}*/
		
		if(action.equalsIgnoreCase("login")) {
			resp.sendRedirect(userService.createLoginURL(requestURI));
		} else if(action.equalsIgnoreCase("logout")) {
			resp.sendRedirect(userService.createLogoutURL(requestURI));
		}
		
	}
}
